package org.mte.swift.builder.model.app;

import java.util.HashMap;

import org.mte.sakn.util.ListSet;
import org.mte.swift.builder.model.app.component.PrimaryKeyReference;
import org.mte.swift.builder.model.app.component.PropertyTag;
import org.mte.swift.builder.model.jpa.Entity;
import org.mte.swift.builder.model.placeholder.Placeholder;
import org.mte.swift.builder.model.template.Template;

public class AppModel {
	
	protected Entity entity = null;
	
	protected PrimaryKeyReference primaryKeyReference = null;
	
	protected ListSet<PropertyTag> propertyTagList = null;
	
	protected HashMap<Placeholder, String> placeholderMap = null;

	protected ListSet<Template> templateSet = null;
	
	protected String targetPackage = null;
	
	protected String webDir = null;
	
	protected String webPath = null;
	
	public AppModel() {		
	}
	
	public Entity getEntity() {
		return entity;
	}

	public void setEntity(Entity entity) {
		this.entity = entity;
	}

	public ListSet<PropertyTag> getPropertyTagList() {
		if (propertyTagList == null) {
			propertyTagList = new ListSet<PropertyTag>();
		}
		return propertyTagList;
	}

	public void setPropertyTagList(ListSet<PropertyTag> propertyTagList) {
		this.propertyTagList = propertyTagList;
	}

	public HashMap<Placeholder, String> getPlaceholderMap() {
		return placeholderMap;
	}

	public void setPlaceholderMap(HashMap<Placeholder, String> placeholderMap) {
		this.placeholderMap = placeholderMap;
	}
	
	public void putPlaceholder(Placeholder placeholder, String value) {
		if (placeholderMap == null)  {
			placeholderMap = new HashMap<Placeholder, String>();
		}
		placeholderMap.put(placeholder, value);
	}
	
	public String getPlaceholderValue(Placeholder placeholder) {
		String value = null;
		if (placeholderMap != null) {
			value = placeholderMap.get(placeholder);
		}
		return value;
	}

	public ListSet<Template> getTemplateSet() {
		if (templateSet == null) {
			templateSet = new ListSet<Template>();
		}
		return templateSet;
	}

	public PrimaryKeyReference getPrimaryKeyReference() {
		return primaryKeyReference;
	}

	public void setPrimaryKeyReference(PrimaryKeyReference primaryKeyReference) {
		this.primaryKeyReference = primaryKeyReference;
	}
	
	public String getWebDir() {
		return webDir;
	}

	public void setWebDir(String webDir) {
		this.webDir = webDir;
	}
	
	public String getWebPath() {
		return webPath;
	}
	
	public void setWebPath(String webPath, String webDir) {
		this.webPath = webPath + webDir + "/";
	}

	public String getTargetPackage() {
		return targetPackage;
	}

	public void setTargetPackage(String rootTargetPackage, String targetPackage) {
		String rightSide = (targetPackage != null && !targetPackage.equals("")) ? 
				rootTargetPackage + "." + targetPackage :
				rootTargetPackage;	
		this.targetPackage = rightSide;
	}
}
